<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	#import {
		position: relative;
		top: 1.4px;
	}
</style>
<div class="page-header">
	<h1>
		学生管理
		<!-- 教师权限不可编辑 -->
		<?php if($rmxUser['user_type'] != USER_TYPE_TEACHER): ?>

			<?php if(! $rmxSchool['school_from']): ?>
				<a href="<?=admin_url('school/student_edit')?>" class="btn btn-info a-custom">
					<i class="ace-icon fa fa-plus"></i> 新增学生
				</a>
				<span class="dropdown dropdown-custom">
					<div class="btn btn-info btn-dropdown"  data-toggle="dropdown">
						<i class="ace-icon fa fa-database"></i> 模板导入与导出&nbsp;&nbsp;<i class="ace-icon fa fa-caret-down"></i>
					</div>
					<ul class="dropdown-menu">
						<li>
							<a href="javascript:" id="import">
								<i class="ace-icon fa fa-upload"></i> 导入学生数据
							</a>
						</li>
						<li>
							<a href="https://resource.rongmixiao.com/2020/05/20/2d107da09a6c0fc8ea1949fdfd8d9e27.xls" target="_blank">
								<i class="ace-icon fa fa-download"></i> 导出学生数据模板
							</a>
						</li>
					</ul>
				</span>
			<?php endif ?>
			<!-- 同步学校才支持导入物理卡号 -->
			<?php if($rmxSchool['school_from']): ?>
				<span class="dropdown dropdown-custom">
					<div class="btn btn-info btn-dropdown"  data-toggle="dropdown">
						<i class="ace-icon fa fa-database"></i> 卡号导入与导出&nbsp;&nbsp;<i class="ace-icon fa fa-caret-down"></i>
					</div>
					<ul class="dropdown-menu">
						<li>
							<a href="javascript:" id="import-realcard">
								<i class="ace-icon fa fa-upload"></i> 导入物理卡号
							</a>
						</li>
						<li>
							<!-- <a href="https://resource.rongmixiao.com/2019/12/11/1e0f44f9953302ddbbe98153f8b38291.xls" target="_blank">
								<i class="ace-icon fa fa-download"></i> 导出卡号模板
							</a> -->
							<a href="javascript:;" id="export_realcard" target2="_blank">
								<i class="ace-icon fa fa-download"></i> 导出卡号模板
							</a>
						</li>
					</ul>
				</span>
			<?php endif ?>

			<a href="javascript:;" class="btn btn-info a-custom" id="export_student" target2="_blank">
				<i class="ace-icon fa fa-download"></i> 导出学生数据
			</a>
			<a href="<?=admin_url('school/import_student_faceimg_batch')?>" class="btn btn-info a-custom">
				<i class="ace-icon fa fa-download"></i> 批量导入学生人脸图片
			</a>
		<?php endif ?>	
	</h1>
</div>
<div class="col-xs-12 content-filter">
	<!-- 筛选 -->
	<div class="widget-box">
		<div class="widget-header">
			<h4 class="widget-title">内容筛选</h4>
			<div class="widget-toolbar">
				<a href="#" data-action="collapse">
					<i class="ace-icon fa fa-chevron-up"></i>
				</a>
				<a href="#" data-action="close">
					<i class="ace-icon fa fa-times"></i>
				</a>
			</div>
		</div>
		<div class="widget-body">
			<div class="widget-main">
				<div class="form-inline" id="data-search">
					<div class="form-inline keyword-search-div">
						<label class="keyword-search-label">名称&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="keyword-search-box">
							<div class="div-search">
								<input style="float:left;height:30px;width:180px;border:1px solid #669FC7;padding:0 30px 0 14px;border-radius:10px 0 0 10px !important;-moz-border-radius:10px 0 0 10px;" type="text" name="student-name" placeholder="搜索学生名称..." autocomplete="off">
								<span id="empty-search" style="position:relative;right:64px;cursor:pointer;display:none;">×</span>
								<button id="btn-search" class="btn-search" style="outline:none;float:left;height:30px;width:44px;border:1px solid #669FC7;background-color:#669FC7;border:0;border-radius:0 10px 10px 0;-moz-border-radius:0 10px 10px 0;">
									<i class="ace-icon fa fa-search nav-search-icon white"></i>
								</button>
								<!-- 同步学校不能修改 -->
								<?php if(empty($rmxSchool['school_from'])): ?>
									<button type="button" class="btn btn-info btn-sm" style="height: 30px;position:absolute;left:268px;" id="batch-update-class-btn">
										<i class="ace-icon fa fa-edit bigger-110 "></i> 批量更新学生班级
									</button>

									<button type="button" class="btn btn-danger btn-sm" style="height: 30px;position:absolute;left:440px;" id="del-student-batch-btn">
										<i class="ace-icon fa fa-times bigger-110 "></i> 批量删除学生
									</button>
								<?php endif ?>
							</div>
						</div>
					</div>
					<!-- 管理员权限 -->
					<?php if($rmxUser['user_type'] == USER_TYPE_SCHOOL): ?>
						<div class="form-inline keyword-search-div" id="div-grade">
							<label class="keyword-search-label">年级&nbsp;&nbsp;&nbsp;&nbsp;</label>
							<div class="keyword-search-box">
								<a href="javascript:;" class="keyword-search-keyword keyword-search-grade active" data-id="0">全部</a>
								<?php if(isset($gradeList)): ?>
									<?php foreach($gradeList as $grade): ?>
										<a href="javascript:;" class="keyword-search-keyword keyword-search-grade"  data-id="<?=$grade['id']?>"><?=$grade['grade_name']?></a>
									<?php endforeach; ?>
								<?php endif ?>
							</div>
						</div>
						<div class="form-inline keyword-search-div" id="div-normal-class">
							<label class="keyword-search-label">行政班</label>
							<div class="keyword-search-box">
								<a href="javascript:;" class="keyword-search-keyword keyword-search-normal-class active" data-id="0">全部</a>
							</div>
						</div>
						<!-- <div class="form-inline keyword-search-div" id="div-teaching-class">
							<label class="keyword-search-label">教学班</label>
							<div class="keyword-search-box">
								<a href="javascript:;" class="keyword-search-keyword keyword-search-teaching-class active" data-id="0">全部</a>
							</div>
						</div>
						<div class="form-inline keyword-search-div" id="div-elective-class">
							<label class="keyword-search-label">选修班</label>
							<div class="keyword-search-box">
								<a href="javascript:;" class="keyword-search-keyword keyword-search-elective-class active" data-id="0">全部</a>
								<?php foreach($electiveClassList as $electiveClass): ?>
									<a href="javascript:;" class="keyword-search-keyword keyword-search-elective-class"  data-id="<?=$electiveClass['id']?>"><?=$electiveClass['class_name']?></a>
								<?php endforeach; ?>
							</div>
						</div> -->
					<?php else: ?>	
						<!-- 教师权限 -->
						<div class="form-inline keyword-search-div" id="div-normal-class">
							<label class="keyword-search-label">行政班</label>
							<div class="keyword-search-box div-classes">
								<a href="javascript:;" class="keyword-search-keyword keyword-search-class active" data-id="0">全部</a>
								<?php foreach($rmxUser['classArr'] as $class): ?>
									<a href="javascript:;" class="keyword-search-keyword keyword-search-class" data-id="<?=$class['id']?>"><?=$class['name']?></a>
								<?php endforeach; ?>
							</div>
						</div>
					<?php endif ?>
					<!-- <div class="form-inline keyword-search-div">
						<label class="keyword-search-label">绑定人</label>
						<div class="keyword-search-box" id="div-bind">
							<a href="javascript:;" class="keyword-search-keyword active" data-value="0">全部</a>
								<a href="javascript:;" class="keyword-search-keyword" data-value="1">有</a>
								<a href="javascript:;" class="keyword-search-keyword" data-value="2">无</a>
						</div>
					</div> -->
					<div class="form-inline keyword-search-div">
						<label class="keyword-search-label">人脸图</label>
						<div class="keyword-search-box" id="div-face">
							<a href="javascript:;" class="keyword-search-keyword active" data-value="0">全部</a>
								<a href="javascript:;" class="keyword-search-keyword" data-value="1">有</a>
								<a href="javascript:;" class="keyword-search-keyword" data-value="2">无</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="col-xs-12">
	<!-- 学校表格 -->
	<table id="dynamic-table" class="table table-striped table-bordered table-hover mt10">
		<thead>
			<tr>
				<th class="center">
					<label class="check-th">
						<input type="checkbox" class="ace" id="check-first">
						<span class="lbl"></span>
					</label>
				</th>
				<th>学生名称</th>
				<th>就读班级</th>
				<!-- <th style="width:10%;">教学班</th>
				<th style="width:10%;">选修班</th> -->
				<th>联系电话</th>
				<th>学号</th>
				<!-- <th>职务</th> -->
				<th>物理卡号</th>
				<!-- <th>身份证号</th> -->
				<!-- <th style="width:6%;">有效时间</th> -->
				<th>人脸图片</th>
				<!-- <th style="width:5%;">座位号</th>
				<th>绑定人</th> -->
				<!-- <th>创建时间</th> -->
				<th width="215px">操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>
<!-- 批量更新班级弹窗 -->
<div id="myModal" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					批量更新选中的学生班级
				</div>
			</div>
			<div class="modal-body no-padding">
				<div class="row">
					<div class="col-xs-12">
						<form class="form-horizontal mt10" id="image-form">
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">所属角色：</label>
								<div class="col-sm-6">
								<div class="col-sm-12 tree">
									<ul id="role-tree"></ul>
								</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="modal-footer no-margin-top" >
				<a href="javascript:;" class="btn btn-sm btn-primary" id="batch-update-class">
					<i class="ace-icon fa fa-check"></i> 保存
				</a>
			</div>
		</div>
	</div>
</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var schoolId = 0;
	// 班级数据
	var normalClassJson = <?= $gradeNormalClassList ?>;
	var teachingClassJson = <?= $gradeTeachingClassList ?>;
	$(function(){
		var table = $('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('school/get_student_list')?>',
			"columns": [
	            {"data": function(ret){
					return "<div class='center'><label class='check-td'><input type='checkbox' class='ace check-list' value=" + ret.id + "><span class='lbl'></span></label></div>";
				}},	
				{"data": function(ret){
					if(ret.gender == '男') {
						var gender = ' <i class="fa fa-mars blue"></i>';
					} else {
						var gender = ' <i class="fa fa-venus red"></i>';
					}
					return ret.realname + gender;
	            }},
	            {"data": function(ret){
	            	return '<span class="label label-success" style="margin-right:5px">'+ ret.className +'</span>'
	            }},
	            // {"data": function(ret){
	            // 	var teachName = "";
	            // 	for(var i in ret.teachClass) teachName += '<span class="label label-purple mr10">'+ ret.teachClass[i].class_name +'</span>';
	            // 	return teachName
				// }},
	            // {"data": function(ret){
	            // 	var electiveName = "";
	            // 	for(var i in ret.electiveClass) electiveName += '<span class="label label-info mr10">'+ ret.electiveClass[i].class_name +'</span>';
	            // 	return electiveName
	            // }},
				{"data": "mobile"},
				{"data": "username"},
	            // {"data": "job"},
				{"data": "realcard"},
				// {"data": "shenfenzheng"},
				// {"data": "expire_date"},
	            {"data": function(ret){
	            	return ret.face_image ? '<span class="label label-success">已录入</span>' : '';
	            }},
				// {"data": function(ret){
				// 	return ret.seat_no
				// }},
	            // {"data": "bindUsers"},
	            // {"data": "createtime"},
	            {"data": function(ret){
					var action = '';
					// 如果是教师权限，只有任课班级的才能修改或删除
					// if(ret.role_change) {
						action += '<a class="mr20" target="_blank" href="<?=admin_url('school/student_edit')?>/'+ ret.id +'"><i class="fa fa-edit"></i> 修改</a>';
						action += '<a class="reset-password mr20" data-id="'+ ret.id +'" href="javascript:;"><i class="fa fa-asterisk"></i> 重置密码</a>';
						<?php if(! $rmxSchool['school_from']): ?>
							action += '<a class="text-danger delete-student" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.realname + '><i class="fa fa-times"></i> 删除</a>';
						<?php endif ?>
					// }
					return action;
	            }},
			],
			"callback": function() {
			}
		});

		
		// // 内容筛选
		// $("#data-search-btn").click(function(){
		// 	table.setAjaxData({
		// 		"gradeId": $("#data-search-grade").val(),
		// 		"classId": $("#data-search-class").val(),
		// 		"teachId": $("#data-search-teach").val(),
		// 		"electiveId": $("#data-search-elective").val(),
		// 		"keyword": $("#data-search-name").val(),
		// 	});
		// })
		// 年级班级联动
		$("#data-search-grade").change(function(){
			var gradeId = $(this).val();
			var classSelect = $("#data-search-class");
			var teachSelect = $("#data-search-teach");
			var getUrl = "<?=admin_url('school/get_class_list')?>/" + gradeId;
			ajax_get(getUrl, {hideLoading: true}, function(res){
				var optionHtml = "";
				classSelect.html('<option value="">全部班级</option>');
				teachSelect.html('<option value="">全部班级</option>');

				for(var i in res.data) {
					var classData = res.data[i];
					if(classData.class_type == '<?=CLASSES_TYPE_NORMAL?>') classSelect.append('<option value="'+ classData.id +'">'+ classData.class_name +'</option>');
					if(classData.class_type == '<?=CLASSES_TYPE_TEACHING?>') teachSelect.append('<option value="'+ classData.id +'">'+ classData.class_name +'</option>');
				}
			})
		})
		// 点击关键字
		$("body").on("click", ".keyword-search-keyword", function(){
			var id = $(this).data("id");
			// 高亮当前点击对象
			$(this).parent().find(".keyword-search-keyword").removeClass("active");
			$(this).addClass("active");
			// 如果是点击年级
			if($(this).hasClass("keyword-search-grade")) {
				// 先清空班级列表
				$(".keyword-search-normal-class:gt(0)").remove();
				$(".keyword-search-teaching-class:gt(0)").remove();
				// 获取班级列表
				var normalClassList = normalClassJson[id];
				var teachingClassList = teachingClassJson[id];
				for(var i in normalClassList) $(".keyword-search-normal-class:first").parent().append('<a href="javascript:;" class="keyword-search-keyword keyword-search-normal-class" data-id="'+ normalClassList[i].id +'">'+ normalClassList[i].name +'</a>');
				for(var i in teachingClassList) $(".keyword-search-teaching-class:first").parent().append('<a href="javascript:;" class="keyword-search-keyword keyword-search-teaching-class" data-id="'+ teachingClassList[i].id +'">'+ teachingClassList[i].name +'</a>');
				// 选中全部班级
				var studentName = $("[name=student-name]").val();
				var gradeId = $("#div-grade .active").data("id");
				var electiveId = $("#div-elective-class .active").data("id");
				var bind = $("#div-bind .active").data("value");
				var face = $("#div-face .active").data("value");
				// 筛选班级
				table.setAjaxData({
					"keyword": studentName,
					"gradeId": gradeId,
					"electiveId": electiveId,
					"bind": bind,
					"face": face
				});
			} else {
				var studentName = $("[name=student-name]").val();
				var gradeId = $("#div-grade .active").data("id");
				var classId = $("#div-normal-class .active").data("id");
				var teachId = $("#div-teaching-class .active").data("id");
				var electiveId = $("#div-elective-class .active").data("id");
				var bind = $("#div-bind .active").data("value");
				var face = $("#div-face .active").data("value");
				// 筛选班级
				table.setAjaxData({
					"classId": classId,
					"teachId": teachId,
					"electiveId": electiveId,
					'keyword': studentName,
					"gradeId": gradeId,
					"bind": bind,
					"face": face
				});
			}
		});
		// 敲回车就搜索
		$("[name=student-name]").keypress(function (e) {
                if (e.which == 13) {
                    $("#btn-search").trigger("click");
                }
		});
		// 清空搜索框
		$("[name=student-name]").keyup(function() {
			if($(this).val().length > 0) {
				$("#empty-search").show();
				$("#empty-search").click(function(){
					$("[name=student-name]").val('');
					$(this).hide();
					// 重置搜索结果
					var gradeId = $("#div-grade .active").data("id");
					var classId = $("#div-normal-class .active").data("id");
					var teachId = $("#div-teaching-class .active").data("id");
					var electiveId = $("#div-elective-class .active").data("id");
					var bind = $("#div-bind .active").data("value");
					var face = $("#div-face .active").data("value");
					table.setAjaxData({
						"gradeId": gradeId,
						"classId": classId,
						"teachId": teachId,
						"electiveId": electiveId,
						"bind": bind,
						"face": face
					});
				})
			} else {
				$("#empty-search").hide();
			}
		}); 
		// 搜索标题
		$("#btn-search").click(function() {
			var studentName = $("[name=student-name]").val();
			var gradeId = $("#div-grade .active").data("id");
			var classId = $("#div-normal-class .active").data("id");
			var teachId = $("#div-teaching-class .active").data("id");
			var electiveId = $("#div-elective-class .active").data("id");
			var bind = $("#div-bind .active").data("value");
			var face = $("#div-face .active").data("value");
			table.setAjaxData({
				'keyword': studentName,
				"gradeId": gradeId,
				"classId": classId,
				"teachId": teachId,
				"electiveId": electiveId,
				"bind": bind,
				"face": face
			})
		});
		// 重置登录密码
		$("body").on("click", ".reset-password", function(){
			var id = $(this).data("id");
			layer.confirm('确定将密码重置为“123456”吗？', function(index){
				layer.close(index);
				// 提交数据
				var actionUrl = "<?=admin_url('school/reset_student_password')?>";
				var actionData = {"id": id};
				ajax_get(actionUrl, actionData);
			});
		});
		// 删除学生
		$("body").on('click', '.delete-student', function() {
			var id = $(this).data('id');
			var title = $(this).data('title');
			var posturl = "<?= admin_url("school/delete_student_action") ?>";
			var data = {
				'id': id
			};
			layer.confirm('确定删除：' + title + '？', { title:"提示", offset: '160px' }, function(){
				ajax_post(posturl, data, function() {
					// 刷新页面
					window.location.href = "<?= admin_url('school/student') ?>";
				});
			});
		});

		// 批量导入物理卡号
		var upFromurl = '<?=UP_FORM_URL?>';
		var signature = '<?=$signature?>';
		var policy = '<?=$policy?>';
		$("#import-realcard").uploader({
			"server": upFromurl,
			"authorization": signature,
			"policy": policy,
			// 只支持上传 xls
			"accept": "xls",
			"callback": function(response) {
				// 上传后的文件名
				var fileLink = upyunUrl + response.url;
				// 导入课表数据
				ajax_post("<?= admin_url('school/import_realcard') ?>", { fileLink: fileLink}, function(res) {
					// 刷新页面
					location.reload();
				});
			}
		});

		// 导入学生数据
		$("#import").uploader({
			"server": upFromurl,
			"authorization": signature,
			"policy": policy,
			// 只支持上传 xls
			"accept": "xls",
			"callback": function(response) {
				// 上传后的文件名
				var fileLink = upyunUrl + response.url;
				ajax_post("<?= admin_url('import/import_student') ?>", { fileLink: fileLink}, function(res) {
					// 刷新页面
					location.reload();
				});
			}
		});
		// 设置选择文件按钮大小
		setTimeout(function(){
			$(".webuploader-pick").next().width(158).height(32);
		}, 100);
		// 全选复选款
		$("#check-first").change(function(e) { 
			var checked =  $("#check-first").is(':checked'); 
			if(checked){
				$('.check-list').each(function (i){
					$(this).prop('checked', true);
				})
			} else{
				$('.check-list').each(function (i){
					$(this).prop('checked', false);
				})
			}
		});
		// 监听子复选框
		setTimeout(() => {
			$(".check-list").change(function(e) { 
				var checked = $(this).is(':checked');
				if(checked) {
					var allChecked = true;
					$('.check-list').each(function (i){
						if(!$(this).is(':checked')) {
							allChecked = false;
						}
					})
					if(allChecked) {
						$("#check-first").prop('checked', true);
					} else {
						$("#check-first").prop('checked', false);
					}
				} else {
					$("#check-first").prop('checked', false);
				}
			});
		}, 500);
		setTimeout(() => {
			$(".check-list").change(function(e) { 
				var checked = $(this).is(':checked');
				if(checked) {
					var allChecked = true;
					$('.check-list').each(function (i){
						if(!$(this).is(':checked')) {
							allChecked = false;
						}
					})
					if(allChecked) {
						$("#check-first").prop('checked', true);
					} else {
						$("#check-first").prop('checked', false);
					}
				} else {
					$("#check-first").prop('checked', false);
				}
			});
		}, 2000);

		// 初始化选择年级控件
		$("#batch-update-class-btn").selectSourceGrade({
			"title": '选择班级',
			"modalDataUrl": '<?= admin_url('school/select_grade_plugin_data_source') ?>',
			"resultDom": $("[name=grade]"),
			"callback": function(res) {
				var classId = 0;
				for(var key in res) {
					classId = key;
				}
				var list = $("input:checkbox.check-list:checked");
				var lis =  $(".tree-selected");
				var idArr = new Array();
				list.each(function(){
					idArr.push($(this).val());
				});
				var postUrl = "<?=admin_url('school/batch_update_student_class')?>";
				var postData = {"id_arr": idArr, "class_id": classId};
				ajax_post(postUrl, postData, function(res){
					window.location.reload();
				})
			}
		});

		// 批量修改班级
		$("#batch-update-class").click(function(){
			var list = $("input:checkbox.check-list:checked");
			var lis =  $(".tree-selected");
			var idArr = new Array();
			var roleArr = new Array();
			list.each(function(){
				idArr.push($(this).val());
			});
			lis.each(function(){
				roleArr.push($(this).attr('id'));
			});
			var postUrl = "<?=admin_url('school/update_teacher_role')?>";
			var postData = {"id_arr": idArr, "role_arr": roleArr};
			ajax_post(postUrl, postData, function(res){
				window.location.reload();
			})
		});
		// 导出学生数据
		$("#export_student").click(function() {
			var studentName = $("[name=student-name]").val();
			var gradeId = $("#div-grade .active").data("id");
			var classId = $("#div-normal-class .active").data("id");
			var teachId = $("#div-teaching-class .active").data("id");
			var electiveId = $("#div-elective-class .active").data("id");
			var bind = $("#div-bind .active").data("value");
			var face = $("#div-face .active").data("value");
			$url = "<?=admin_url('school/export_student?')?>";
			$queryStr = '';
			$queryArr = [];
			$str = '';
			if(studentName) {
				$str = "keyword=" + studentName;
				$queryArr.push($str);
			}
			if(gradeId) {
				$str = "gradeId=" + gradeId;
				$queryArr.push($str);
			}
			if(classId) {
				$str = "classId=" + classId;
				$queryArr.push($str);
			}
			if(teachId) {
				$str = "teachId=" + teachId;
				$queryArr.push($str);
			}
			if(electiveId) {
				$str = "electiveId=" + electiveId;
				$queryArr.push($str);
			}
			if(bind) {
				$str = "bind=" + bind;
				$queryArr.push($str);
			}
			if(face) {
				$str = "face=" + face;
				$queryArr.push($str);
			}
			$queryStr = $queryArr.join("&");
			// console.log($queryStr);return;
			window.location.href  = $url + $queryStr;
		});

		// 导出卡号数据
		$("#export_realcard").click(function() {
			var studentName = $("[name=student-name]").val();
			var gradeId = $("#div-grade .active").data("id");
			var classId = $("#div-normal-class .active").data("id");
			var teachId = $("#div-teaching-class .active").data("id");
			var electiveId = $("#div-elective-class .active").data("id");
			var bind = $("#div-bind .active").data("value");
			var face = $("#div-face .active").data("value");
			$url = "<?=admin_url('school/export_student_realcard?')?>";
			$queryStr = '';
			$queryArr = [];
			$str = '';
			if(studentName) {
				$str = "keyword=" + studentName;
				$queryArr.push($str);
			}
			if(gradeId) {
				$str = "gradeId=" + gradeId;
				$queryArr.push($str);
			}
			if(classId) {
				$str = "classId=" + classId;
				$queryArr.push($str);
			}
			if(teachId) {
				$str = "teachId=" + teachId;
				$queryArr.push($str);
			}
			if(electiveId) {
				$str = "electiveId=" + electiveId;
				$queryArr.push($str);
			}
			if(bind) {
				$str = "bind=" + bind;
				$queryArr.push($str);
			}
			if(face) {
				$str = "face=" + face;
				$queryArr.push($str);
			}
			$queryStr = $queryArr.join("&");
			// console.log($queryStr);return;
			window.location.href  = $url + $queryStr;
		});

		// 管理员才可解绑
		<?php if($rmxUser['user_type'] == USER_TYPE_SCHOOL): ?>
			// 解绑
			$("body").on('click', '.unbind', function() {
				var id = $(this).data('id');
				var nickname = $(this).text();
				var that = $(this);
				// alert(nickname);
				layer.confirm('确定解绑：' + nickname + '？', function(index){
					layer.close(index);
					// 提交数据
					var actionUrl = "<?=admin_url('school/unbind_action')?>";
					var actionData = {"id": id};
					ajax_get(actionUrl, actionData, function() {
						that.empty();
					});
				});
			});
		<?php endif ?>	

		// 批量删除学生
		$("#del-student-batch-btn").click(function(){
			var list = $("input:checkbox.check-list:checked");
			var idArr = new Array();
			list.each(function(){
				idArr.push($(this).val());
			});
			var len = idArr.length;
			var postUrl = "<?=admin_url('school/delete_student_batch')?>";
			var postData = {"id_arr": idArr};
			if(len == 0) {
				ajax_post(postUrl, postData, function(res){
					window.location.reload();
				});
				return;
			}
			layer.confirm('确认批量删除学生？删除个数：' + len, { title:"提示", offset: '160px' }, function(){
				ajax_post(postUrl, postData, function(res){
					window.location.reload();
				})
			});

		});
	})
</script>